package com.example.common.fraction;

import com.example.common.model.JavaCourseModel;
import com.example.common.model.bean.JVideo;
import com.example.commonlib.base.presenter.SuperPresenter;
import com.example.commonlib.net.ServiceResponse;
import ohos.aafwk.content.Intent;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * Created by linlongxin on 2016/9/14.
 */

public class VideoPresenter extends SuperPresenter<VideoFraction> {

    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "test001");
    private int page = 0;


    @Override
    public void onCreate(Intent intent) {
        HiLog.error(LABEL, "*****************VideoPresenter onCreate******************");
        getData(true);
    }

    public void getData(final boolean isRefresh){
        HiLog.error(LABEL, "*****************VideoPresenter getData******************");
        if(isRefresh){
            page = 0;
        }

        JavaCourseModel.getInstance().getVideoList(page, new ServiceResponse<JVideo[]>(){
            @Override
            public void onNext(JVideo[] jVideos) {
                super.onNext(jVideos);
                getView().showContent();
                getView().setData(jVideos);
                page++;
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                HiLog.error(LABEL, "*****************VideoPresenter onError******************");
                getView().showError();
            }
        });
    }
}
